<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id='box'></div>
    <script>
        var img = new Image(200, 200);
        img.onload = function () { alert("img is loaded") };
        img.onerror = function () { alert("error!") };
        img.src = "http://pic1.win4000.com/wallpaper/f/51c3bb99a21ea.jpg";
        function show() { alert("body is loaded"); };
        window.onload = show;
        box.appendChild(img)
    </script>
</body>

</html>